//
//  VideosDetailViewController.m
//  SYiDaiy
//
//  Created by dllo on 16/8/31.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "VideosDetailViewController.h"
#import "TAMacro.h"

#import "AFNetworking.h"

#import "VideoView.h"
#import "UIView+Frame.h"



#import "Videosesarray.h"



#import "VideoDetailCollectionViewCell.h"
#import "CustomWebview.h"


@interface VideosDetailViewController ()<UICollectionViewDataSource>



@property (nonatomic,strong) NSMutableArray<Videosesarray *> *videosDetailArray;

@property (nonatomic,strong) CustomWebview *webview;


@property (nonatomic,strong) UICollectionView *videoCollection;
@property (nonatomic,strong) UICollectionViewFlowLayout *flow;


@end

@implementation VideosDetailViewController

#pragma mark ----视频详情页视图加载
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatCollectionView];
}

- (void)creatCollectionView
{
    self.navigationController.navigationBarHidden = NO;
    _flow = [UICollectionViewFlowLayout new];
    _flow.itemSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT - 49 - 64);
    _flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _flow.minimumInteritemSpacing = 0;
    _flow.minimumLineSpacing = 0;
    _flow.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    _videoCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49) collectionViewLayout:_flow];
    _videoCollection.backgroundColor = [UIColor whiteColor];
    [self.videoCollection reloadData];
    [self videosDetailNetworkGet];


    _videoCollection.dataSource = self;
    _videoCollection.pagingEnabled = YES;
    _videoCollection.contentOffset = CGPointMake(_rowValue * SCREEN_WIDTH, 0);
    [self.view addSubview:_videoCollection];
    [_videoCollection registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"_videoCollectionCell"];
    
    
    
    
    


    
    
    
}
#pragma mark -------返回collectioncell的方法
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
     UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"_videoCollectionCell" forIndexPath:indexPath];
    _webview = [[CustomWebview alloc] initWithFrame:cell.bounds];
    [cell.contentView addSubview:_webview];
    NSInteger row = indexPath.row;
    Videosesarray *videosesarray = _videosDetailArray[row];
    [_webview passStr:videosesarray.link_share];
    return cell;

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _videosDetailArray.count;
}








#pragma mark -----视频详情页网络请求
- (void)videosDetailNetworkGet
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *requestURLString = @"http://watch-cdn.idailywatch.com/api/list/video/zh-hans?page=1&ver=iphone&app_ver=15";
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager GET:requestURLString parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        _videosDetailArray = [NSMutableArray array];
        for (NSDictionary *dic in responseObject) {
            Videosesarray *videosesarray = [Videosesarray modelWithDic:dic];
            [_videosDetailArray addObject:videosesarray];
        }
        NSLog(@"+++++++++++%@",_videosDetailArray[0].title);
        
        [_videoCollection reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
